package com.zhao.common.support;

import javax.servlet.ReadListener;
import javax.servlet.ServletInputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;

public class CachedServletInputStream extends ServletInputStream {

    private ByteArrayInputStream byteArrayInputStream;

    public CachedServletInputStream(ByteArrayOutputStream byteArrayOutputStream) {
        byteArrayInputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
    }

    @Override
    public int read() throws IOException {
        return byteArrayInputStream.read();
    }

    @Override
    public boolean isFinished() {
        return false;
    }

    @Override
    public boolean isReady() {
        return false;
    }

    @Override
    public void setReadListener(ReadListener listener) {

    }
}
